package com.study;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import java.net.Authenticator;

/**
 * @author MI
 * @ClassName CustomerRealm.java
 * @createTime 2021年08月20日 12:19:00
 */
public class CustomerRealm extends AuthorizingRealm {


    // 授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //获取用户
        String principal = (String) token.getPrincipal();
        System.out.println(principal);
        if ("xiaochen".equals(principal)) {
            // 参数1 数据库中用户名，参数2 数据库中密码，参数3 relam名字
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(principal,"123",this.getName());
            return info;
        }

        return null;
    }
}
